//
//  ByMyDocumentaryDetailTitleCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/23.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByMyDocumentaryDetailTitleCell.h"

@implementation ByMyDocumentaryDetailTitleCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByMyDocumentaryDetailTitleCell";
    ByMyDocumentaryDetailTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
       
    }
    return self;
}


- (void)initViews{
    
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(0);
        make.right.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(0);
    }];
    backgroundView.backgroundColor = [UIColor whiteColor];
    backgroundView.layer.cornerRadius = 5;
    
    ByDocumentaryCellTitleView *titleView = [[ByDocumentaryCellTitleView alloc] initWithFrame:CGRectMake(5, 0, SCREEN_WIDTH - 10, 50)];
    [backgroundView addSubview:titleView];
    self.titleView = titleView;
    titleView.timeLabel.hidden = YES;
    titleView.recordLabel.hidden = YES;
    titleView.tapViewBlock = ^(){
        if (self.tapViewBlock) {
            self.tapViewBlock();
        }
    };
    
    UIImageView *iconView = [[UIImageView alloc] init];
    [backgroundView addSubview:iconView];
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backgroundView).offset(13);
        make.right.equalTo(backgroundView).offset(-10);
        make.size.mas_equalTo(CGSizeMake(88, 23));
    }];
    //iconView.image = [UIImage imageNamed:@"zhongjiang 1拷贝12"];
    self.iconView = iconView;
    
    CGFloat content_height = 0;
    NSString *str = @"";
    if (_isMyDocumentary) {
        str = _netModel.reason;
    }else{
        str = [NSString stringWithFormat:@"跟单于:%@【%@】",_netModel.nickname,_netModel.sn];
    }
    content_height = [str getRectOfStringWithSize:CGSizeMake(SCREEN_WIDTH - 32, 1000) font:12].size.height + 25;
    
    UILabel *contentLabel = [[UILabel alloc] init];
    [backgroundView addSubview:contentLabel];
    contentLabel.numberOfLines = 0;
    contentLabel.text = str;
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backgroundView).offset(55);
        make.left.equalTo(backgroundView).offset(16);
        make.right.equalTo(backgroundView).offset(-16);
        make.height.mas_equalTo(@(content_height));
    }];
    contentLabel.font = FONT(12);
    contentLabel.textColor = BY_TEXT_COLOR;
    
    if (!_isMyDocumentary) {
        contentLabel.textColor = BY_THEME_COLOR;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:contentLabel.text];
        //设置颜色
        [attributedString addAttribute:NSForegroundColorAttributeName value:BY_TEXT_COLOR range:[contentLabel.text rangeOfString: @"跟单于:"]];
        contentLabel.attributedText = attributedString;
        
    }
    
    UIView *grayView = [[UIView alloc] init];
    [backgroundView addSubview:grayView];
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(16);
        make.right.equalTo(backgroundView).offset(-16);
        make.bottom.equalTo(backgroundView).offset(-20 - 30);
        make.height.mas_equalTo(@75);
    }];
    grayView.backgroundColor = rgba(239, 239, 239, 1);
    
   
    CGFloat width = 0;
    if (_isMyDocumentary) {
        width = (SCREEN_WIDTH - 32) / 3.0;
    }else{
        width = (SCREEN_WIDTH - 32) / 4.0;
    }
    
    ByDocumentaryUserTitleValue *leftView = [[ByDocumentaryUserTitleValue alloc] initWithFrame:CGRectMake(0, 0, width, 75)];
    [grayView addSubview:leftView];
    leftView.titleLabel.textColor = [UIColor grayColor];

    ByDocumentaryUserTitleValue *centerView = [[ByDocumentaryUserTitleValue alloc] initWithFrame:CGRectMake(width, 0, width, 75)];
    [grayView addSubview:centerView];
    centerView.titleLabel.textColor = [UIColor grayColor];
    
    ByDocumentaryUserTitleValue *rightView = [[ByDocumentaryUserTitleValue alloc] initWithFrame:CGRectMake(width * 2, 0, width, 75)];
    [grayView addSubview:rightView];
    rightView.titleLabel.textColor = [UIColor grayColor];

    if (!_isMyDocumentary){
        
        leftView.valueLabel.text = @"奖金收入";
        centerView.valueLabel.text = @"佣金扣点";
        rightView.valueLabel.text = @"赚取佣金";
        ByDocumentaryUserTitleValue *rightView1 = [[ByDocumentaryUserTitleValue alloc] initWithFrame:CGRectMake(width * 3, 0, width, 75)];
        [grayView addSubview:rightView1];
        rightView1.titleLabel.textColor = [UIColor grayColor];
        rightView1.valueLabel.text = @"实际收入";
        self.rightView1 = rightView1;
        
        
    }else{
        
        leftView.valueLabel.text = @"奖金收入";
        centerView.valueLabel.text = @"赚取佣金";
        rightView.valueLabel.text = @"合计";
    }
    
  
    
    self.leftView = leftView;
    self.centerView = centerView;
    self.rightView = rightView;
    
    
    UILabel *notesLabel = [[UILabel alloc] init];
    [self.contentView addSubview:notesLabel];
    [notesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(grayView.mas_bottom).offset(7);
        make.left.equalTo(grayView.mas_left).offset(0);
        make.right.equalTo(grayView.mas_right).offset(0);
        make.bottom.equalTo(self.contentView).offset(-15);
    }];
    notesLabel.font = FONT(11);
    notesLabel.numberOfLines = 0;
    notesLabel.textColor = [UIColor grayColor];
    notesLabel.text = @"大神方案盈利大于或等于140%，跟单人需要支付奖金的10%作为佣金，其中8%奖励给大神，2%作为平台推广费";
   
    
}

- (void)setIsMyDocumentary:(BOOL)isMyDocumentary{
    _isMyDocumentary = isMyDocumentary;
    
    
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    
     [self initViews];

    [self.titleView.iconView sd_setImageWithURL:[NSURL URLWithString:netModel.head_pic] placeholderImage:HEAD_ICOM_IMAGE];
    self.titleView.nickLabel.text = netModel.nickname;
    self.titleView.timeLabel.text = [NSString stringWithFormat:@"截止时间:%@",[NSDate getDateForStringFotmatWithTimeInterval:netModel.end_time.integerValue formatter:@"MM-dd HH:mm"]];
    
    self.leftView.titleLabel.text = [NSString stringWithFormat:@"%@元", netModel.total_amount];
    self.rightView.titleLabel.text = [NSString stringWithFormat:@"%@元", netModel.commission];
    
    if (netModel.pay_status.integerValue == 1) {
        if (netModel.is_result.integerValue == 0) {
            
            self.centerView.titleLabel.text = @"未开奖";
            self.iconView.image = [UIImage imageNamed:@"dengdaikaijian等待开奖"];
            
        }else{
            if (netModel.lottery_result.integerValue == 0) {
                self.centerView.titleLabel.text = @"未中奖";
                self.iconView.image = [UIImage imageNamed:@"zaijiezaili 拷贝未中奖"];
                
            }else{
                self.centerView.titleLabel.text = @"已中奖";
                self.iconView.image = [UIImage imageNamed:@"zhongjiang 1拷贝12"];
            }
        }
    }else if (netModel.pay_status.integerValue == 0){
        
        self.centerView.titleLabel.text = @"未支付";
        
    }else if (netModel.pay_status.integerValue == 2){
        
        self.centerView.titleLabel.text = @"交易关闭";
    }
    
    
    
    if (_isMyDocumentary) {
        self.leftView.titleLabel.text = [NSString stringWithFormat:@"%.2f元",netModel.win_amount.floatValue];
        self.centerView.titleLabel.text = [NSString stringWithFormat:@"%.2f元",netModel.commission.floatValue];
        self.rightView.titleLabel.text = [NSString stringWithFormat:@"%.2f元", netModel.all_money.floatValue];
    }else{
        if (netModel.amount) {
             self.leftView.titleLabel.text = [NSString stringWithFormat:@"%.2f元",netModel.amount.floatValue];
        }
        self.centerView.titleLabel.text = [NSString stringWithFormat:@"%@%%",netModel.rate];
        self.rightView.titleLabel.text = [NSString stringWithFormat:@"%.2f元", netModel.commission.floatValue];
        self.rightView1.titleLabel.text = [NSString stringWithFormat:@"%.2f元", netModel.income.floatValue];
    }
    
   
   
    
}

@end
